import Vue from 'vue'
import { MessageBox } from 'mint-ui';
import router from '@/store/router'
export default {
    getCleanData(context) {
        Vue.prototype.$newHttp.post('/cmItem/cleaning/list', {})
            .then(res => {
                context.commit('setData', res.data);
            })
            .catch(err => { console.log(err) });
    },
    getPayData(context, params) {
        Vue.prototype.$newHttp.post('/cmItem/commonItems/detail', params)
            .then(res => {
                context.commit('setPayData', res.data);
            })
            .catch(err => { console.log(err) });
    },
    getTaoCanListData(context, params) {
        Vue.prototype.$newHttp.post('/cmItem/setMeal/list', params)
            .then(res => {
                context.commit('setTaoCanListData', res.data);
            })
            .catch(err => { console.log(err) });
    },
    getMealSmallItemsData(context, params) {
        Vue.prototype.$newHttp.post('/cmItem/smallItems/detail', params)
            .then(res => {
                context.commit('setMealSmallItemsData', res.data);
            })
            .catch(err => { console.log(err) });
    },
    getMealDetailData(context, params) {
        Vue.prototype.$newHttp.post('/cmItem/setMeal/detail', params)
            .then(res => {
                context.commit('setMealDetailData', res.data);
            })
            .catch(err => { console.log(err) });
    },
    getUserMealListData(context) {
        Vue.prototype.$newHttp.post('/cmItem/user/list', {})
            .then(res => {
                context.commit('setUserMealListData', res.data);
            })
            .catch(err => { console.log(err) });
    },
    getFreeCleaningData(context) {
        Vue.prototype.$newHttp.post('/cmItem/freeCleaning/make', {})
            .then(res => {
                context.commit('setFreeCleaningData', res.data);
            })
            .catch(err => { console.log(err) });
    },
    baojieMessage(context, params) {
        Vue.prototype.$newHttp.post('/cmItem/cleaning/make', params)
            .then(res => {
                context.commit('setSelectBao', res.data);
            }).catch(err => { console.log(err) });
    },
    cleanOrderSubmit(context, params) {
        Vue.prototype.$newHttp.post('/order/makeCmOrder', params)
            .then(res => {
                if (res.status === 0) {
                    MessageBox.alert(res.message).then(() => {
                        router.push({ path: '/baojie' });
                    });
                } else if (res.status === 1) {
                    MessageBox.alert('预约成功').then(() => {
                        context.commit('setOrderNumber', res.data.orderNumber);
                        router.push({ path: '/cleanSuccess', query: { orderNumber: res.data.orderNumber } });
                    });
                }
            }).catch(err => { console.log(err) });
    },
    cleanOrderData(context, params) {
        Vue.prototype.$newHttp.post('/order/detail', params)
            .then(res => {
                if (res.status === 0) {
                    MessageBox.alert(res.message);
                } else if (res.status === 1) {
                    context.commit('setOrderDetail', res.data);
                }
            }).catch(err => { console.log(err) });
    }
}